<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <style>
        .regionC1   {width: 110px;}
        .regionC2   {width: 620px;
                    text-align: right;}
        .lvlC1      {width: 110px;}
        .lvlC2      {width: 250px;
                    text-align: right;}
    </style>
    <h:head>
        <script name="jquery/jquery.js" library="primefaces"></script>

        <h:outputStylesheet name="./css/default.css"/>
        <h:outputStylesheet name="./css/cssLayout.css"/>        
        <h:outputScript library="js" name="./jsControles.js"/>
    </h:head>

        <h:form id="frmAddress">
            <p:panel style="width: 770px">
                <h:panelGrid columns="2" columnClasses="regionC1,regionC2"
                         style="width: 750px; table-layout: auto;" >
                <p:outputLabel for="region" value="Регион: " />
                <p:selectOneMenu id="region" style="width: 99%"
                                 value="#{mbVAddress.regionId}"
                                 filter="true"  
                                 filterMatchMode="startsWith" >
                    <p:ajax listener="#{mbVAddress.onRegionChange}" update="county district city" />
                    <f:selectItems value="#{mbVAddress.fias.getRegions().entrySet()}" var="reg" 
                                   itemLabel="#{reg.value.offname} #{reg.value.shortname}" 
                                   itemValue="#{reg.key}" />
                </p:selectOneMenu>        
            </h:panelGrid>
                <h:panelGrid columns="4" columnClasses="lvlC1,lvlC2,lvlC1,lvlC2"
                         style="width: 750px; table-layout: fixed;" >
                <p:outputLabel for="county" value="Округ: " />
                <p:selectOneMenu id="county" style="width: 99% "
                                 value="#{mbVAddress.countyId}" 
                                 filter="true" 
                                 filterMatchMode="startsWith"
                                 disabled="true">
                    <f:selectItem itemLabel="Выбирете округ" itemValue="#{null}" 
                                  noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getCountys().entrySet()}" var="cou" 
                                   itemLabel="#{cou.value.offname}  #{cou.value.shortname}" 
                                   itemValue="#{cou.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="innercity" value="Внутригородской р-н: " />
                <p:selectOneMenu id="innercity" style="width: 99%"
                                 value="#{mbVAddress.innerCityId}" 
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <p:ajax listener="#{mbVAddress.onInnerCityChange()}" update="street" />
                    <f:selectItem itemLabel="Выбирете внутригородской р-н" 
                                  itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getInnerCitys().entrySet()}" var="incit" 
                                   itemLabel="#{incit.value.offname} #{incit.value.shortname}" 
                                   itemValue="#{incit.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="district" value="Район: " />
                <p:selectOneMenu id="district" style="width: 99%"
                                 value="#{mbVAddress.districtId}"
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <p:ajax listener="#{mbVAddress.onDistrictChange()}" 
                            update="city innercity locality" />
                    <f:selectItem itemLabel="Выбирете район" itemValue="#{null}" 
                                  noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getDistricts().entrySet()}" var="dis" 
                                   itemLabel="#{dis.value.offname}  #{dis.value.shortname}" 
                                   itemValue="#{dis.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="locality" value="Населенный пункт: " />
                <p:selectOneMenu id="locality" style="width: 99%"
                                 value="#{mbVAddress.localityId}"
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <p:ajax listener="#{mbVAddress.onLocalityChange()}" 
                            update="street addGround" />
                    <f:selectItem itemLabel="Выбирете населенный пункт" 
                                  itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getLocalitys().entrySet()}" var="loc" 
                                   itemLabel="#{loc.value.offname} #{loc.value.shortname}"
                                   itemValue="#{loc.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="city" value="Город: " />
                <p:selectOneMenu id="city" style="width: 99%"
                                 value="#{mbVAddress.cityId}" 
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <p:ajax listener="#{mbVAddress.onCityChange()}" 
                            update="innercity locality street" />
                    <f:selectItem itemLabel="Выбирете город" itemValue="#{null}"
                                  noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getCitys().entrySet()}" var="cit" 
                                   itemLabel="#{cit.value.offname} #{cit.value.shortname}" 
                                   itemValue="#{cit.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="street" value="Улица: " />
                <p:selectOneMenu id="street" style="width: 99%"
                                 value="#{mbVAddress.streetId}" 
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <f:selectItem itemLabel="Выбирете улицу" itemValue="#{null}" 
                                  noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getStreets().entrySet()}" var="str" 
                                   itemLabel="#{str.value.offname} #{str.value.shortname}"
                                   itemValue="#{str.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="addGround" value="Доп. территория: " />
                <p:selectOneMenu id="addGround" style="width: 99%"
                                 value="#{mbVAddress.addGroundId}" 
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <p:ajax listener="#{mbVAddress.onAddGroundChange()}" 
                            update="streetAddGround" />
                    <f:selectItem itemLabel="Выбирете доп. территорию" 
                                  itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getAddGrounds().entrySet()}" var="agr" 
                                   itemLabel="#{agr.value.offname} #{agr.value.shortname}" 
                                   itemValue="#{agr.key}"/>
                </p:selectOneMenu>

                <p:outputLabel for="streetAddGround" value="Улицы на доп. территории: " />
                <p:selectOneMenu id="streetAddGround" style="width: 99%"
                                 value="#{mbVAddress.streetAddGroundId}"
                                 filter="true" 
                                 filterMatchMode="startsWith">
                    <f:selectItem itemLabel="Выбирете улицу на доп. территории" 
                                  itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{mbVAddress.fias.getStreetAddGrounds().entrySet()}"                                
                                   var="sga"                                   
                                   itemLabel="#{sga.value.offname} #{sga.value.shortname}" 
                                   itemValue="#{sga.key}"/>
                </p:selectOneMenu>
            </h:panelGrid>
            <hr />
            <h:panelGrid columns="4" style="width: 750px; table-layout: fixed;" 
                         columnClasses="lvlC1,lvlC2,lvlC1,lvlC2">                
                <p:outputLabel for="numAddrLevl1" value="Номер дома: " />
                <h:panelGroup >
                    <p:inputText id="numAddrLevl1" value="#{mbVAddress.numAddrLevl1}" 
                                 label="numAddrLevl1" style="width: 20%"/>
                    <p:spacer width="10"/>  
                    <p:selectOneMenu value="#{mbVAddress.typeAddrLevl1}" 
                                     style="width: 70%" styleClass="select_address">
                        <f:selectItem itemLabel="Дом" itemValue="д" />
                        <f:selectItem itemLabel="Гаражно-строительный кооператив" itemValue="ГСК" />
                        <f:selectItem itemLabel="казарма" itemValue="казарма" />
                        <f:selectItem itemLabel="Участок" itemValue="уч" />
                        <f:selectItem itemLabel="Владение" itemValue="вл" />
                        <f:selectItem itemLabel="бокс" itemValue="бокс" />
                        <f:selectItem itemLabel="военная часть" itemValue="в/ч" />
                        <f:selectItem itemLabel="сооружение" itemValue="сооружение" />
                    </p:selectOneMenu>
                </h:panelGroup>                

                <p:outputLabel for="numAddrLevl2" value="Номер корпуса: " />
                <h:panelGroup>
                    <p:inputText id="numAddrLevl2" value="#{mbVAddress.numAddrLevl2}"
                                 label="numAddrLevl2" style="width: 20%"/>
                    <p:spacer width="10"/> 
                    <p:selectOneMenu value="#{mbVAddress.typeAddrLevl2}" 
                                     style="width: 70%" styleClass="select_address">
                        <f:selectItem itemLabel="Корпус" itemValue="корп" />
                        <f:selectItem itemLabel="Дом" itemValue="д" />
                        <f:selectItem itemLabel="Участок" itemValue="уч" />
                        <f:selectItem itemLabel="Владение" itemValue="вл" />
                        <f:selectItem itemLabel="Гараж" itemValue="гараж" />
                        <f:selectItem itemLabel="бокс" itemValue="бокс" />
                        <f:selectItem itemLabel="строение" itemValue="строение" />
                        <f:selectItem itemLabel="сооружение" itemValue="сооружение" />
                    </p:selectOneMenu>
                </h:panelGroup>

                <p:outputLabel for="numAddrLevl3" value="Номер строения: " />
                <h:panelGroup>
                    <p:inputText id="numAddrLevl3" value="#{mbVAddress.numAddrLevl3}"
                                 label="numAddrLevl3" style="width: 20%"/>
                    <p:spacer width="10"/> 
                    <p:selectOneMenu value="#{mbVAddress.typeAddrLevl3}" 
                                     style="width: 70%" styleClass="select_address">
                        <f:selectItem itemLabel="Строение" itemValue="строен" />
                        <f:selectItem itemLabel="Корпус" itemValue="корп" />
                        <f:selectItem itemLabel="Блок" itemValue="блок" />
                        <f:selectItem itemLabel="Литера" itemValue="литера" />
                    </p:selectOneMenu>
                </h:panelGroup>
                
                <p:outputLabel for="numApartment" value="Номер квартиры: " />
                <h:panelGroup>
                    <p:inputText id="numApartment" value="#{mbVAddress.numApartment}"
                                 label="numApartment" style="width: 20%"/>
                    <p:spacer width="10"/> 
                    <p:selectOneMenu value="#{mbVAddress.typeApartment}" style="width: 70%"
                                     styleClass="select_address" >
                        <f:selectItem itemLabel="Квартира" itemValue="кв" />
                        <f:selectItem itemLabel="Бокс" itemValue="бокс" />
                        <f:selectItem itemLabel="Комната" itemValue="к" />
                        <f:selectItem itemLabel="Помещение" itemValue="пом" />
                    </p:selectOneMenu>
                </h:panelGroup>                
            </h:panelGrid>  
            <hr />
            <p:inputTextarea id="otherAddress" value="#{mbVAddress.otherAddress}" rows="3" style="width: 99%" 
                             maxlength="4000" autoResize="false" />
            <p:spacer height="10px" width="10px" />
            <h:panelGroup layout="block" style="text-align: right">
                <p:commandButton value="Заполнить" styleClass="button"
                                 action="#{mbVAddress.createOtherAddress()}" 
                                 update="otherAddress"/>
                <p:spacer width="10px" />
                <p:commandButton value="Принять" styleClass="button"                                 
                                 action="#{mbVAddress.saveAddress()}"/>
            </h:panelGroup>
        </p:panel>
    </h:form>

    <div>
        <p:ajaxStatus style="display:block;width:16px;height:16px;
                      position:fixed;right:50%;bottom:50%">  
            <f:facet name="start">                    
                <h:graphicImage value="./../resources/images/loader.gif" />  
            </f:facet>  

            <f:facet name="complete">  
                <h:outputText value="" />  
            </f:facet>  
        </p:ajaxStatus>
        <p:ajaxStatus onstart="PF('statusDialog').show()" 
                      onsuccess="PF('statusDialog').hide()" />
        <p:dialog widgetVar="statusDialog" modal="true" draggable="false" 
                  closable="false" resizable="false" showHeader="false"
                  style="opacity: 0" />
    </div>

</html>

